<?php

!defined('IN') && exit("Access denied");

$page_no = (int)$_GET['page_no'];
$order_id = $_GET['order_id'];

if ($order_id) 
{## 查看订单
    $order = $_ENV['db']->fetch("SELECT * FROM `order` WHERE `leader_id` = '{$_G['uid']}' AND `order_sn` = '{$order_id}'");
    if (!$order) exit('系统错误，订单不存在');
    $order_detail = $_ENV['db']->fetchAll("SELECT * FROM order_detail WHERE order_id = '{$order['order_id']}'");
    $template->my_page = 'front/order_detail';
    $template->order = $order;
    $template->order_detail = $order_detail;
    $template->page_no = $page_no;
    $template->title = '订单详情 - 会员中心';
} 
else 
{## 订单列表
    $total = $_ENV['db']->fetchCol("SELECT count(order_id) as total FROM `order` WHERE leader_id = '{$_G['uid']}'"); 
    $pager = new class_pager();
    $pager->setConfig($page_no,$total,40);
    $pager->setUrl('my.php?act=order&page_no=tpt','tpt');

    $orders = $_ENV['db']->fetchAll("SELECT * FROM `order` WHERE `leader_id` = '{$_G['uid']}' order by `order_id` desc LIMIT ".$pager->getLimit()." OFFSET ".$pager->getOffset());

    $template->my_page = 'front/order_list';
    $template->pager = $pager->output('page_num');
    $template->orders = $orders;
    $template->page_no = $page_no;
    $template->title = '我的订单 - 会员中心';
}